package com.example.demo.mapper;

import com.example.demo.entity.Storage;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StorageMapper {
    // 创建仓库
    @Insert("INSERT INTO storage(sid, squantity, sweight, scbelong, shbelong, isdeleted) " +
            "VALUES(#{sid}, #{squantity}, #{sweight}, #{scbelong}, #{shbelong}, #{isdeleted})")
    int createStorage(Storage storage);

    // 删除仓库
    @Delete("DELETE FROM storage WHERE sid = #{sid}")
    int deleteStorage(Integer sid);

    // 逻辑删除仓库
    @Update("UPDATE storage SET isdeleted = 1 WHERE sid = #{sid}")
    void updateIsdeleted(Integer sid);

    // 更新仓库信息
    @Update("UPDATE storage SET squantity = #{squantity}, sweight = #{sweight}, " +
            "scbelong = #{scbelong}, shbelong = #{shbelong} WHERE sid = #{sid}")
    int updateStorage(Storage storage);

    // 根据ID查询仓库
    @Select("SELECT * FROM storage WHERE sid = #{sid}")
    Storage findStorageById(Integer sid);

    // 查询所有仓库
    @Select("SELECT * FROM storage WHERE isdeleted = 0")
    List<Storage> findAllStorages();

    // 根据公司ID查询仓库
    @Select("SELECT * FROM storage WHERE scbelong = #{cid} AND isdeleted = 0")
    List<Storage> findStoragesByCompanyId(Integer cid);
}